<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/1/18
 * Time: 14:05
 */

namespace app\model\index;


class Keyword extends Base
{
    protected $append = [
        'status',
        'baiduyingxiao_showreasons',
        'keywords'
    ];

    public function getBaiduyingxiaoShowreasonsAttr($value){
        return explode(',',$value);
    }

    public function getKeywordsAttr($value){
        if (empty($value))return [];
        return json_decode($value,true);
    }
    public function getAllAttr($value,$data){
        if ($data['zz_all'] > $value)
            return $data['zz_all'];
        else
            return $value;
    }

    public function getPcAttr($value,$data){
        if ($data['zz_pc'] > $value)
            return $data['zz_pc'];
        else
            return $value;
    }

    public function getPhoneAttr($value,$data){
        if ($data['zz_phone'] > $value)
            return $data['zz_phone'];
        else
            return $value;
    }

    public static function getPriceType($type){
        $arr = [
            1 => 'price',
            2 => 'pc_price',
            3 => 'phone_price'
        ];
        return $arr[$type];
    }

    public function getStatusAttr($value,$data){
        $count['baidu'] = OrderInfo::where('keyword',$data['keyword'])
            ->where('status',2)
            ->where('end_date','>',date('Y-m-d'))
            ->where('keyword_area','baidu')
            ->count();
        $count['douyin'] = OrderInfo::where('keyword',$data['keyword'])
            ->where('status',2)
            ->where('end_date','>',date('Y-m-d'))
            ->where('keyword_area','douying')
            ->count();
        return $count;
    }
}